﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    public enum Name
    {
        刘备 = 1,
        孙权,
        曹操
    }
    public enum act
    {
        剪刀 = 1,
        石头,
        布
    }
    class Program
    {
        static void Main(string[] args)
        {


            Console.WriteLine("----------welcome to game world---------");
            Console.WriteLine("**********************");
            Console.WriteLine("*****猜拳游戏开始*****");
            Console.WriteLine("**********************");
            Console.WriteLine("出拳规则：1.剪刀 2.石头 3.布");
            Console.WriteLine("全选择对方玩家：1.刘备 2.孙权 3.曹操");


            //电脑玩家的命名
            int computer = int.Parse(Console.ReadLine());

            Name name = Name.刘备;

            name = (Name)computer;


            //游戏玩家的命名
            Console.WriteLine("输入您的名称");
            string player = Console.ReadLine();

            player P = new player(player);


            Console.WriteLine(player + " " + "VS" + " " + name);
            //比赛场数
            int time = 0;

            int[] Play = { 0 };//玩家分数
            int[] Computer = { 0 };//电脑分数

            //游戏准备开始
            perpare(name, P, time, Play, Computer);

        }

        private static void perpare(Name name, player P, int time, int[] Play, int[] Computer)
        {
            Console.WriteLine("开始游戏吗？ Y/N");

            string key = Console.ReadLine();


            switch (key)
            {
                case "y":

                    gamebegin(name, P, time, Play, Computer);
                    break;

                case "n":

                    Console.WriteLine("结束");
                    break;
                default:
                    break;
            }
        }
        //游戏结束 询问是否重新再玩
        private static void gameover(Name name, player P, int time, int[] Play, int[] Computer)
        {

            Console.WriteLine("是否开启新一轮？Y/N");
            string T = Console.ReadLine();
            switch (T)
            {
                case "y":
                    gamebegin(name, P, time, Play, Computer);

                    break;
                case "n":

                    result(name, P, time, Play, Computer);

                    gameAgain(name, P, time, Play, Computer);

                    break;

                default:
                    break;
            }
        }
        //再次游戏
        private static void gameAgain(Name name, player P, int time, int[] Play, int[] Computer)
        {
            Console.WriteLine("是否开启下一局？Y/N");
            string T = Console.ReadLine();
            switch (T)
            {
                case "y":
                    gamebegin(name, P, time, Play, Computer);
                    break;
                case "n":
                    Console.WriteLine("游戏结束了");
                    break;

                default:
                    break;
            }
        }
        //比赛结果
        private static void result(Name name, player P, int time, int[] Play, int[] Computer)
        {

            Console.WriteLine("========================");
            Character character = new Character((name)name);

            Console.WriteLine(P.Player + " " + "VS" + " " + name);

            Console.WriteLine("对战次数：" + time);

            judgment j = new judgment();


            Console.WriteLine("姓名\t得分");

            Console.WriteLine(P.Player + "   " + Play[0]);
            Console.WriteLine(name + "   " + Computer[0]);

            if (Play[0] > Computer[0])
            {
                Console.WriteLine(P.Player + "胜利" + " | " + name + "猪一样");
            }
            else
            {
                Console.WriteLine("结果" + name + "胜利" + " | " + P.Player + "猪一样");
            }
            if (Play[0] == Computer[0])
            {
                Console.WriteLine("双方平手");
            }



        }
        //开始游戏
        private static void gamebegin(Name name, player P, int time, int[] Play, int[] Computer)
        {


            Console.WriteLine("请出拳：1.剪刀 2.石头 3.布(输入相应数字)");

            //玩家输入

            int p = int.Parse(Console.ReadLine());


            //电脑玩家
            Character character = new Character((name)name);

            //裁判
            judge(P.fingerGuess(p), character.fingerGuess(character), Play, Computer);
            // J.judge(P.fingerGuess(p), character.fingerGuess(character),  Play, Computer);
            
            //比赛次数
            time++;


            gameover(name, P, time, Play, Computer);

        }
        //裁判判断
        public static void judge(int player, int computer, int[] Play, int[] Computer)
        {


            if (player == 1 & computer == 2)
            {
                Console.WriteLine("恭喜你输了，猪一样");
                Computer[0]++;

            }
            else if (player == 1 & computer == 3)
            {
                Console.WriteLine("恭喜你赢了");
                Play[0]++;

            }
            else if (player == 1 & computer == 1)
            {
                Console.WriteLine("平手");
            }
            //石头
            else if (player == 2 & computer == 3)
            {
                Console.WriteLine("恭喜你输了，猪一样");
                Computer[0]++;
            }
            else if (player == 2 & computer == 1)
            {
                Console.WriteLine("恭喜你赢了");
                Play[0]++;
            }
            else if (player == 2 & computer == 2)
            {
                Console.WriteLine("平手");
            }
            //布
            else if (player == 3 & computer == 1)
            {
                Console.WriteLine("恭喜你输了，猪一样");
                Computer[0]++;
            }
            else if (player == 3 & computer == 2)
            {
                Console.WriteLine("恭喜你赢了");
                Play[0]++;
            }
            else if (player == 3 & computer == 3)
            {
                Console.WriteLine("平手");
            }

        }
    }


}
